home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / DLGWIND.CPP < prev    next >
C/C++ Source or Header  |  1993-10-14  |  56KB  |  2,195 lines

  1. #include "allwind.h"
  2.  
  3. #define TWindow_type 1
  4. #define TStatic_type 2
  5. #define TListBox_type 3
  6. #define TComboBox_type 4
  7. #define TButton_type 5
  8. #define TScrollBar_type 6
  9. #define TGroupBox_type 7
  10. #define TRadioButton_type 8
  11. #define TCheckBox_type 9
  12. #define TDialog_type 10
  13.  
  14. //NODE *xxx;
  15.  
  16. HICON hCursorSave = 0;           /* handle for saved cursor */
  17.  
  18. char *Windowname[]={"?","Window","Static","ListBox","ComboBox","Button","ScrollBar","GroupBox","RadioButton","CheckButton","Dialog"};
  19.  
  20. char mainwindow[]="ROOT";
  21.  
  22. /* class structure for storing information about users windows */
  23.  
  24. class slink
  25.    {
  26.    friend class slist;
  27.    
  28.    slink *next;
  29.    slink *prev;
  30.    char *key;
  31.    char *parent;
  32.    int type;
  33.    ent e;
  34.    
  35.    slink(ent a, slink* n, slink* p, char *k, char *par, int t)
  36.       {
  37.       e=a;
  38.       next=n;
  39.       prev=p;
  40.       key=k;
  41.       parent=par;
  42.       type=t;
  43.       }
  44.    };
  45.  
  46. class slist
  47.    {
  48.    slink* last;
  49.    public:
  50.    void insert(ent a, char* k, char* par, int t);
  51.    ent get(char* k);
  52.    ent get2(char* k, int t);
  53.    char *getparent(char* par);
  54.    void zap(char* k);
  55.    void list(char* k, int lev);
  56.    void clear();
  57.    
  58.    slist()
  59.       {
  60.       last = NULL;
  61.       }
  62.    
  63.    slist(ent a, char *k, char *par, int t)
  64.       {
  65.       last=new slink(a, NULL, NULL, k, par, t);
  66.       last->next=last;
  67.       last->prev=last;
  68.       }
  69.    
  70.    ~slist()
  71.       {
  72.       clear();
  73.       }
  74.    };
  75.  
  76. void slist::insert(ent a, char* k, char *par, int t)
  77.    {
  78.    if (last)
  79.       {
  80.       last->next = new slink(a, last->next, last, k, par, t);
  81.       last->next->next->prev = last->next;
  82.       }
  83.    else
  84.       {
  85.       last = new slink(a, NULL, NULL, k, par, t);
  86.       last->next = last;
  87.       last->prev = last;
  88.       }
  89.    }
  90.  
  91. ent slist::get2(char *k,int t)
  92.    {
  93.    slink* f;
  94.    
  95.    if (last==NULL) return NULL;
  96.    
  97.    f = last;
  98.    
  99.    do
  100.       {
  101.       if (strcmp(f->key,k)==0)
  102.          {
  103.          if (f->type == t) return(f->e); else return(NULL);
  104.          }
  105.       f = f->next;
  106.       } while (f != last);
  107.    
  108.    return NULL;
  109.    }
  110.  
  111. ent slist::get(char *k)
  112.    {
  113.    slink* f;
  114.    
  115.    if (last==NULL) return NULL;
  116.    
  117.    f = last;
  118.    
  119.    do
  120.       {
  121.       if (strcmp(f->key,k)==0)
  122.          {
  123.          return(f->e);
  124.          }
  125.       f = f->next;
  126.       } while (f != last);
  127.    
  128.    return NULL;
  129.    }
  130.  
  131. char *slist::getparent(char *k)
  132.    {
  133.    slink* f;
  134.    
  135.    if (last==NULL) return NULL;
  136.    
  137.    f = last;
  138.    
  139.    do
  140.       {
  141.       if (strcmp(f->parent,k)==0)
  142.          {
  143.          return(f->key);
  144.          }
  145.       f = f->next;
  146.       } while (f != last);
  147.    
  148.    return NULL;
  149.    }
  150.  
  151. void slist::zap(char* k)
  152.    {
  153.    slink* f;
  154.    slink* p;
  155.    char* t;
  156.    
  157.    if (last==NULL) return;
  158.    
  159.    f = last;
  160.    p = NULL;
  161.    
  162.    do
  163.       {
  164.       if (strcmp(f->key,k)==0)
  165.          {
  166.          p = f;
  167.          break;
  168.          }
  169.       f = f->next;
  170.       } while (f != last);
  171.    
  172.    // delete any children first
  173.    
  174.    while ((t=getparent(k)) != NULL) { zap(t); }
  175.    
  176.    if (p != NULL)
  177.       {
  178.       f = p->next;
  179.       
  180.       if (f == p)
  181.          {
  182.          last = NULL;
  183.          }
  184.       else
  185.          {
  186.          if (p == last) last = p->prev;
  187.          
  188.          p->prev->next = p->next;
  189.          f->prev = p->prev;
  190.          }
  191.       
  192.       delete p;
  193.       }
  194.    
  195.    }
  196.  
  197. void slist::list(char *k,int level)
  198.    {
  199.    slink* f;
  200.    slink* ff;
  201.    slink* p;
  202.    char temp[128];
  203.    char indent[128];
  204.    int i;
  205.    
  206.    if (last==NULL) return;
  207.    
  208.    f = last;
  209.    p = NULL;
  210.    
  211.    do
  212.       {
  213.       if (strcmp(f->key,k)==0)
  214.          {
  215.          p = f;
  216.          break;
  217.          }
  218.       f = f->next;
  219.       } while (f != last);
  220.    
  221.    if (p != NULL)
  222.       {
  223.       
  224.       indent[0] = '\0';
  225.       for (i=0;i<level;i++) strcat(indent," ");
  226.       
  227.       if (level == 0)
  228.          {
  229.          sprintf(temp,"%s %s",Windowname[p->type],p->key);
  230.          putcombobox(temp);
  231.          }
  232.       
  233.       ff = last;
  234.       
  235.       do
  236.          {
  237.          if (strcmp(ff->parent,k)==0)
  238.             {
  239.             sprintf(temp,"  %s%s %s",indent,Windowname[ff->type],ff->key);
  240.             putcombobox(temp);
  241.             list(ff->key,level+1);
  242.             }
  243.          ff = ff->next;
  244.          } while (ff != last);
  245.       
  246.       }
  247.    }
  248.  
  249. void slist::clear()
  250.    {
  251.    slink* l = last;
  252.    
  253.    if (l == NULL) return;
  254.    
  255.    do
  256.       {
  257.       slink* ll = l;
  258.       l = l->next;
  259.       delete ll;
  260.       }
  261.    while (l!=last);
  262.    
  263.    }
  264.  
  265. // class structures for the controls we support, for the most part they
  266. // are the same as the original with just a key and callback string added
  267.  
  268. class TMxWindow : public TWindow
  269.    {
  270.    public:
  271.    char key[MAX_BUFFER_SIZE];
  272.    TMxWindow(PTWindowsObject AParent, LPSTR AText, PTModule AModule = NULL) :
  273.    (AParent, AText, AModule) {};
  274.    };
  275.  
  276. class TMxDialog : public TDialog
  277.    {
  278.    public:
  279.    char key[MAX_BUFFER_SIZE];
  280.    char callback[MAX_BUFFER_SIZE];
  281.    char caption[MAX_BUFFER_SIZE];
  282.    int x,y,h,w;
  283.    TMxDialog(PTWindowsObject AParent, LPSTR AText, PTModule AModule = NULL) :
  284.    (AParent, AText, AModule) {};
  285.    virtual void SetupWindow();
  286.    };
  287.  
  288. void TMxDialog::SetupWindow()
  289.    {
  290.    SetWindowPos(HWindow, NULL, x, y, w, h, 0);
  291.    SetCaption(caption);
  292.    
  293.    do_execution(callback);
  294.    
  295.    TDialog::SetupWindow();
  296.    }
  297.  
  298. class TMyListBox : public TListBox
  299.    {
  300.    public:
  301.    char key[MAX_BUFFER_SIZE];
  302.    TMyListBox(PTWindowsObject AParent, int AnId, int X, int Y,
  303.    int W, int H, PTModule AModule = NULL) :
  304.    (AParent, AnId, X, Y, W, H, AModule) {};
  305.    };
  306.  
  307. class TMxComboBox : public TComboBox
  308.    {
  309.    public:
  310.    char key[MAX_BUFFER_SIZE];
  311.    TMxComboBox(PTWindowsObject AParent, int AnId, int X, int Y,
  312.    int W, int H, DWORD AStyle, WORD ATextLen, PTModule AModule = NULL) :
  313.    (AParent, AnId, X, Y, W, H, AStyle, ATextLen, AModule) {};
  314.    };
  315.  
  316. class TMyStatic : public TStatic
  317.    {
  318.    public:
  319.    char key[MAX_BUFFER_SIZE];
  320.    TMyStatic(PTWindowsObject AParent, int AnId, LPSTR AText, int X, int Y,
  321.    int W, int H, WORD ATextLen, PTModule AModule = NULL) :
  322.    (AParent, AnId, AText, X, Y, W, H, ATextLen, AModule) {};
  323.    };
  324.  
  325. class TMyButton : public TButton
  326.    {
  327.    public:
  328.    char key[MAX_BUFFER_SIZE];
  329.    char callback[MAX_BUFFER_SIZE];
  330.    //   NODE *callbackx;
  331.    int critical;
  332.    TMyButton(PTWindowsObject AParent, int AnId, LPSTR AText, int X, int Y,
  333.    int W, int H, BOOL IsDefault, PTModule AModule = NULL) :
  334.    (AParent, AnId, AText, X, Y, W, H, IsDefault, AModule) {};
  335.    virtual void DefWndProc(RTMessage Msg);
  336.    };
  337.  
  338. NODE *leventcheck(void)
  339.    {
  340.    MSG msg;
  341.    
  342.    //   checkqueue();
  343.    
  344.    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  345.       {
  346.       TranslateMessage(&msg);
  347.       DispatchMessage(&msg);
  348.       }
  349.    
  350.    return (UNBOUND);
  351.    }
  352.  
  353. /* function that processes our own queued events */
  354.  
  355. void checkqueue()
  356.    {
  357.    callthing *thing;
  358.    int save_yield_flag;
  359.    int sv_val_status;
  360.    
  361.    while (thing=calllists.get())
  362.       {
  363.       
  364.       sv_val_status = val_status;
  365.       
  366.       calllists.zap();
  367.       switch (thing->kind)
  368.          {
  369.          
  370.          // mouse event must not yield while processing
  371.          
  372.          case 1:
  373.             {
  374.             save_yield_flag = yield_flag;
  375.             yield_flag = 0;
  376.             mouse_posx = thing->arg1;
  377.             mouse_posy = thing->arg2;
  378.             do_execution(thing->func);
  379.             yield_flag = save_yield_flag;
  380.             break;
  381.             }
  382.          
  383.          // keyboard  event must not yield while processing
  384.          
  385.          case 2:
  386.             {
  387.             save_yield_flag = yield_flag;
  388.             yield_flag = 0;
  389.             keyboard_value = thing->arg1;
  390.             do_execution(thing->func);
  391.             yield_flag = save_yield_flag;
  392.             break;
  393.             }
  394.          
  395.          // Button, timer or other event ok to yield while processing
  396.          
  397.          case 3:
  398.             {
  399.             do_execution(thing->func);
  400.             break;
  401.